import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

const router = new Router({
  mode: 'history',
  routes: [
    {
      path: '/',
      redirect: '/bishu'
    },
    {
      path: '/index',
      name: 'index',
      meta: { title: "秒台车特惠 新车首付仅1%" },
      component: resolve => require(['@/components/page/index.vue'], resolve)
    },
    {
      path: '/home',
      name: 'home',
      meta: { title: "秒台车特惠 新车首付仅1%" },
      component: resolve => require(['@/components/page/home.vue'], resolve)
    },
    {
      path: '/bishu',
      name: 'bishu',
      meta: { title: "秒台车特惠 新车首付仅1%" },
      component: resolve => require(['@/components/page/bishu.vue'], resolve)
    },
    {
      path: '/cars',
      name: 'cars',
      meta: { title: "秒台车特惠 新车首付仅1%" },
      component: resolve => require(['@/components/page/cars.vue'], resolve)
    },
    {
      path: '/voice',
      name: 'voice',
      meta: {
        title: "七夕鲜花大派送，汽车免费送！",
        isqixi: true
      },
      component: resolve => require(['@/components/page/voice.vue'], resolve)
    },
    {
      path: '/qixiHome',
      name: 'qixiHome',
      meta: {
        title: "七夕鲜花大派送，汽车免费送！",
        isqixi: true
      },
      component: resolve => require(['@/components/page/qixiHome.vue'], resolve)
    },
    {
      path: '/qixiLu',
      name: 'qixiLu',
      meta: {
        title: "七夕鲜花大派送，汽车免费送！",
        isqixi: true
      },
      component: resolve => require(['@/components/page/qixiLu.vue'], resolve)
    },
    {
      path: '/qixiResult',
      name: 'qixiResult',
      meta: {
        title: "七夕鲜花大派送，汽车免费送！",
        isqixi: true
      },
      component: resolve => require(['@/components/page/qixiResult.vue'], resolve)
    },
    {
      path: '/qixiMyshare',
      name: 'qixiMyshare',
      meta: {
        title: "七夕鲜花大派送，汽车免费送！",
        isqixi: true
      },
      component: resolve => require(['@/components/page/qixiMyshare.vue'], resolve)
    },
  ]
})
router.beforeEach((to, from, next) => {//beforeEach是router的钩子函数，在进入路由前执行
  if (to.meta.title) {//判断是否有标题
    document.title = to.meta.title
  }
  if (to.meta.isqixi) {
    var u = navigator.userAgent;
    var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
    // XXX: 修复iOS版微信HTML5 History兼容性问题
    if (isiOS && to.path !== location.pathname) {
      location.assign(to.fullPath)
    } else {
      next()
    }
  } else {
    next()
  }
})

export default router
